package com.gxuwz.weather.config;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

public class RequestDemo7 {
    public static String getWeatherData7(String areaCn) {

        String path = "http://getweather.api.bdymkt.com/lundear/weather7d";

        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.GET, path);
        request.setCredentials("403338ea7328494295c4aa1eddde560b", "5d1347f6997b4ebd9491fe1e6063fbea");
        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json; charset=utf-8");

        // 设置query参数
        request.addQueryParameter("areaCn", areaCn);

        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            return response.getResult();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}